home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dirut / duh13.zip / DUH.BAS next >
BASIC Source File  |  1989-05-01  |  5KB  |  174 lines

  1. ' $Title:' -DELINF-  Delete duplicate files already in ARC files' $Pagesize:74 $Linesize:132
  2. '
  3. '  QB DELINF/e/o/c:0;
  4. '  LINK DELINF,,NUL,advbas;
  5. '
  6. '  Syntax:
  7. '               DELINF [filespec] [/o]
  8. '
  9. 100     defint a-z
  10.         const maxfiles=512
  11.         const true=-1, false=0
  12.  
  13.     const version$="DELINF v1.3 - 5/01/89 - V.Buerg"
  14.  
  15.         dim fl.names$(maxfiles)        ' non-ARC files in current directory
  16.         dim fl.date!(maxfiles)         ' file dates
  17.         dim fl.time(maxfiles)          ' file times
  18.         dim fl.size!(maxfiles)         ' file sizes
  19.  
  20.         on error goto error.traps
  21.  
  22.     i=instr(command$,"/O") : if i then sw.o=true ' get option switches
  23.     i=instr(command$,"/N") : if i then sw.n=true
  24.         cmd$=command$
  25.         if instr(cmd$," ") then cmd$=left$(cmd$,instr(cmd$," ")-1)
  26.         if instr(cmd$,"/") then cmd$=left$(cmd$,instr(cmd$,"/")-1)
  27.  
  28.  
  29. ' --- Build list of non-ARC files in directory
  30.  
  31. 200     fspec$="*.*"                    ' filespec for ARCs
  32.         if cmd$<>"" then fspec$=cmd$
  33.         attr=0 : retcd=0
  34.         call findfirstf (fspec$+chr$(0),attr,retcd) ' first matching file
  35.         if retcd then
  36.           print
  37.           print "No files found!"
  38.           end
  39.         end if
  40.  
  41. get.file:
  42. 300     infile$=space$(12)              ' get first matching file
  43.         call getnamef (infile$,flen)
  44.         fl$=left$(infile$,flen)
  45.     if f<maxfiles then
  46.          f=f+1
  47.          fl.names$(f)=fl$
  48.          call getdatef (month,day,year)
  49.       fl.date!(f)=csng(year-1900)*10000!+csng(month)*100!+csng(day)
  50.          call gettimef (hour,minute,second)
  51.           fl.time(f)=hour*100+minute
  52.          call getsizef (lo,hi)
  53.           lo!=csng(lo)
  54.           if lo<0 then lo!=lo!+65536!
  55.           fl.size!(f)=lo!+csng(hi)*65536!
  56.         end if
  57.  
  58. get.next.file:
  59. 400     call findnextf (retcd)          ' get next matching file
  60.         if retcd=0 then goto get.file
  61.  
  62.         if f=0 then
  63.           print
  64.           print "No ";fspec$;" files found!"
  65.           end
  66.         end if
  67.  
  68. ' ---  Get list of files within ARC files
  69.  
  70. run.arcv:
  71. 500     print
  72.     print version$
  73.         print
  74.     print "Usage:  DELINF [d:\path\filespec] [/O] [/N]
  75.         print
  76.         print "Where d:\path\filespec refers to subdir containing non-ARC"
  77.     print "files that may be in ARC or ZIP files in the current directory."
  78.     print
  79.     print "The default d:\path\filespec is *.*."
  80.     print
  81.     print "Specify /O to delete older files."
  82.     print "Specify /N to delete files of the same name."
  83.  
  84.         print
  85.     print "Stand-by. Getting archive file contents ..."
  86.  
  87.     shell "FV * >temparcv.tmp"
  88.  
  89.         i=0
  90. getspec:
  91.         j=i : i=instr(i+1,fspec$,"\")
  92.         if i then goto getspec else fspec$=left$(fspec$,j)
  93.  
  94. 510     open "temparcv.tmp" for input as #1
  95.     open "DELINF.bat" for output as #2
  96.  
  97.         while not eof(1)
  98.          line input #1,a$
  99.  
  100.          if a$=space$(len(a$)) then goto another
  101.          if left$(a$,5)="Name " then goto another
  102.  
  103.      if left$(a$,9)="Archive: " then         ' new archive file
  104.            arcname$=mid$(a$,11)
  105.            print "Checking: ";arcname$
  106.            goto another
  107.          end if
  108.  
  109.          if left$(a$,12)="============" then    ' directory begins
  110.            while not eof (1)
  111.             line input #1,a$
  112.             if left$(a$,6)="*total" then goto another
  113.             arc.name$=left$(a$,12)
  114.             if instr(arc.name$," ") then arc.name$=left$(arc.name$,instr(arc.name$," ")-1)
  115.  
  116.             arc.size!=val(mid$(a$,15,8))
  117.  
  118.             day=val(mid$(a$,51,2))
  119.         month=(instr("JanFebMarAprMayJunJulAugSepOctNovDec",mid$(a$,54,3)) +2 ) /3
  120.             year=val(mid$(a$,58,2))
  121.             arc.date!=csng(year)*10000!+csng(month)*100!+csng(day)
  122.  
  123.             hour=val(mid$(a$,62,2))
  124.             minute=val(mid$(a$,65,2))
  125.             arc.time=hour*100+minute
  126.  
  127.             for n=1 to f
  128.              if arc.name$=fl.names$(n) then
  129.            if ( arc.date!=fl.date!(n) and (arc.time=fl.time(n) ) _
  130.         or (sw.o and arc.time>fl.time(n)) )_
  131.         or sw.n _
  132.         or (sw.o and fl.date!(n)<arc.date!) then
  133.  
  134.                  print #2,"ERASE ";fspec$;arc.name$
  135.          print " ";fspec$;arc.name$;tab(17);"File: ";str$(fl.date!(n));fl.time(n)/100;
  136.          print " / ";mid$(arcname$,instr(arcname$,".")+1,3);":";
  137.          print arc.date!;arc.time/100
  138.                  nd=nd+1
  139.          exit for
  140.  
  141.                end if
  142.              end if
  143.             next
  144.            wend
  145.          end if
  146. another:
  147.         wend
  148.         close #1
  149. 800     kill "temparcv.tmp"
  150. 810     print #2,"DEL DELINF.BAT"
  151.         close #2
  152.         if nd=0 then
  153.       kill "DELINF.bat"
  154.          else
  155.           print
  156.       print "File DELINF.BAT has been created in the current directory."
  157.         end if
  158. 820     print : print nd;"duplicate files to be deleted."
  159.         end
  160.  
  161. ' --- Error recovery
  162.  
  163. error.traps:
  164. 900     if erl=510 then
  165.           print
  166.       print "No ARC, ZIP, PAK or LZH archive files found!"
  167.           beep
  168.           end
  169.         end if
  170.         if erl=800 then resume 810
  171.         if erl=810 then resume 820
  172.         on error goto 0
  173.         end
  174.